//
//  VoiceItemContentToolView.m
//  ShowYork
//
//  Created by hxh on 2021/5/21.
//  Copyright © 2021 hxh. All rights reserved.
//

#import "VoiceItemContentToolView.h"

@interface VoiceItemContentToolView ()
@property (nonatomic,strong)UIView *line;
@property (nonatomic,strong)UILabel *lb1;
@property (nonatomic,strong)UILabel *lb2;
@property (nonatomic,strong)UILabel *lb3;


@end

@implementation VoiceItemContentToolView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}
- (void)setUI{

    self.lb1 = [[UILabel alloc]init];
    self.lb1.text = @"朗读";
    self.lb1.font = [UIFont boldSystemFontOfSize:16];
    self.lb1.textColor = C51;
    [self addSubview:self.lb1];
    
    self.lb2 = [[UILabel alloc]init];
    self.lb2.text = @"鉴赏";
    self.lb2.font = [UIFont boldSystemFontOfSize:16];
    self.lb2.textColor = C153;
    [self addSubview:self.lb2];
    
    self.lb3 = [[UILabel alloc]init];
    self.lb3.text = @"评论";
    self.lb3.font = [UIFont boldSystemFontOfSize:16];
    self.lb3.textColor = C153;
    [self addSubview:self.lb3];

    self.line = [[UIView alloc]init];
    self.line.layer.cornerRadius = 1;
    self.line.layer.masksToBounds = YES;
    self.line.backgroundColor = RGBA(238, 157, 59, 1);
    [self addSubview:self.line];
    
    
    [self.lb1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.right.equalTo(self.lb2.mas_left).offset(-40);
    }];
    [self.lb2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
    }];
    
    [self.lb3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self.lb2.mas_right).offset(40);
    }];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.lb1);
        make.size.mas_equalTo(CGSizeMake(12, 2));
        make.top.equalTo(self.lb1.mas_bottom).offset(2);
    }];
    
    self.lb1.userInteractionEnabled = YES;
    self.lb2.userInteractionEnabled = YES;
    self.lb3.userInteractionEnabled = YES;
   
    UITapGestureRecognizer *lb1T = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(lb1Method)];
    UITapGestureRecognizer *lb2T = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(lb2Method)];
    UITapGestureRecognizer *lb3T = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(lb3Method)];

    [self.lb1 addGestureRecognizer:lb1T];
    [self.lb2 addGestureRecognizer:lb2T];
    [self.lb3 addGestureRecognizer:lb3T];
}

- (void)lb1Method{
    self.currentIndex = 0;
    if (self.delegate && [self.delegate respondsToSelector:@selector(changeToolViewAtIndex:)]) {
        [self.delegate changeToolViewAtIndex:0];
    }
}
- (void)lb2Method{
    self.currentIndex = 1;
    if (self.delegate && [self.delegate respondsToSelector:@selector(changeToolViewAtIndex:)]) {
        [self.delegate changeToolViewAtIndex:1];
    }
}
- (void)lb3Method{
    self.currentIndex = 2;
    if (self.delegate && [self.delegate respondsToSelector:@selector(changeToolViewAtIndex:)]) {
        [self.delegate changeToolViewAtIndex:2];
    }
    
}

- (void)setCurrentIndex:(NSInteger)currentIndex{
    _currentIndex = currentIndex;
    
    self.lb1.textColor = currentIndex == 0?C51:C153;
    self.lb2.textColor = currentIndex == 1?C51:C153;
    self.lb3.textColor = currentIndex == 2?C51:C153;
    
    if (currentIndex == 0) {
        [self.line mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.lb1);
            make.size.mas_equalTo(CGSizeMake(12, 2));
            make.top.equalTo(self.lb1.mas_bottom).offset(2);
        }];
    }
    if (currentIndex == 1) {
        [self.line mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.lb2);
            make.size.mas_equalTo(CGSizeMake(12, 2));
            make.top.equalTo(self.lb1.mas_bottom).offset(2);
        }];
    }
    if (currentIndex == 2) {
        [self.line mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.lb3);
            make.size.mas_equalTo(CGSizeMake(12, 2));
            make.top.equalTo(self.lb1.mas_bottom).offset(2);
        }];
    }
    
}

@end
